package cn.itcast.order.service;

import cn.itcast.feign.clients.UserServiceClient;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import org.apache.catalina.mbeans.UserMBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;


    /*public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        //2. 调用restTemplate 访问user模块的 查询功能
        String uri = "http://userservice/user/"+order.getUserId();
        User user = restTemplate.getForObject(uri, User.class);
        //3. 存入 user
        order.setUser(user);
        // 4.返回
        return order;
    }*/

    @Autowired
    private UserServiceClient userServiceClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        //2. 调用Feign 访问user模块的 查询功能
        User user = userServiceClient.queryById(order.getUserId());
        //3. 存入 user
        order.setUser(user);
        // 4.返回
        return order;
    }


}
